package com.Object01.SmallChange;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class SmallChangeSys {
    public static void main(String[] args) {
        boolean loop = true;
        Scanner scanner = new Scanner(System.in);
        String key = "";
        //零钱通明细
        //用字符串拼接
        String details = "-----------零钱通明细--------------";
        //收益入账和消费功能
        double money = 0;
        double balance = 0;
        //获取当前日期
        Date date = null;//表示日期
        //用以下方法进行日期格式化
        SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd HH:mm:ss");//可以用来对日期的格式化
        String name = "";
        //退出
        char c = ' ';
        do {
            System.out.println("\n--------零钱通菜单----------");
            System.out.println("\t1.零钱通明细");
            System.out.println("\t2.收益入账");
            System.out.println("\t3.消   费");
            System.out.println("\t4.退   出");
            System.out.print("请选择（1-4）：");
            key = scanner.next();
            switch (key) {
                case "1":
                    System.out.println(details);
                    break;
                case "2":
                    System.out.println("------收益入账------");
                    System.out.println("入账金额：");
                    money = scanner.nextDouble();
                    if (money <= 0) {
                        System.out.println("输入的入账金额有误！");
                        break;
                    }
                    balance += money;
                    //得到时间：得到当前日期
                    date = new Date();//对格式进行处理
                    details += "\n收益入账\t+" + money + "\t" + sdf.format(date) + "\t余额：" + balance;
                    break;
                case "3":
                    System.out.println("------消----费------");
                    System.out.println("请输入消费的商家名称：");
                    name = scanner.next();
                    System.out.println("请输入消费的价格：");
                    money = scanner.nextInt();
                    if (money > balance || money <= 0) {
                        System.out.println("消费金额不可高于余额！");
                        break;
                    }
                    balance -= money;
                    date = new Date();
                    details += "\n" + name + "\t-" + money + "\t" + sdf.format(date) + "\t余额：" + balance;
                    break;
                case "4":
                    System.out.println("------退----出------");
//                    if (c == 'y'||c == 'Y') {
//                        System.out.println("-------程序退出------");
//                        loop = false;
//                    } else {
//                        System.out.println("程序继续~");
//                    }
                    while (true) {
                        System.out.println("确定要退出程序吗？");
                        c = scanner.next().charAt(0);
                        if (c == 'y' || c == 'n') {
                            break;
                        }
                    }
                    if (c == 'y') {
                        loop = false;
                    }
                default:
                    System.out.println("输入错误！（1-4）");
            }
        } while (loop);
    }
}
